package com.bcxj.chat.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/chat/ollama")
@CrossOrigin(origins = "*") // 允许跨域请求
public class ChatController {

    @Autowired
    private ChatClient chatClient;

    @GetMapping(value = "stream", produces = MediaType.TEXT_PLAIN_VALUE + ";charset=UTF-8")
    public Flux<String> chat(@RequestParam String message) {
        return chatClient.prompt().user(message).stream().content();
    }
}